using NUnit.Framework;
using ValidationFramework;

namespace ExampleLibraryCSharp
{
	[TestFixture]
	public class ValidatableRuleAttributeExample
    {

		public class Person : ValidatableBase
		{
		    [ValidatableRule(UseMemberErrorMessages = true)]
		    [RequiredObjectRule]
		    public Address Address { get; set; }
		}

		public class Address : ValidatableBase
		{
		    [RequiredStringRule]
		    public string Street { get; set; }
		}

        
		[Test]
        public void Run()
        {
			var person = new Person();
			// Person is invalid because Address is null.
			Assert.IsFalse(person.IsValid);

			person.Address = new Address();
			// Person is invalid because Address has no street.
			Assert.IsFalse(person.IsValid);
			// The error message from address is only passed up because 
			// UseMemberErrorMessages is set to true on the ValidatableRule
			Assert.AreEqual("The property 'Street' is required.", person.ErrorMessages[0]);

			// Set the street.
			person.Address.Street = "1 puddle lane";
			// Person is Valid.
			Assert.IsTrue(person.IsValid);

        }
    }
}